using System.Text;
using AndyPike.Presentations.IntroToTDD.Interfaces;
using NUnit.Framework;

namespace AndyPike.Presentations.IntroToTDD.Tests
{
    [TestFixture]
    public class When_testing_the_performance_of_the_string_reversers
    {
        private string data;
        private ILogger logger;
        private const int DATA_LENGTH = 1024*1024*50;
        private const int REPEAT = 5;

        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            logger = new NullLogger();

            var sb = new StringBuilder();
            for(int x = 0; x < DATA_LENGTH; x++)
            {
                sb.Append('X');
            }

            data = sb.ToString();
        }

        private void RepeatReverse(IReverser<string> reverser)
        {
            for (int x = 0; x < REPEAT; x++)
            {
                reverser.Reverse(data);
            }
        }

        [Test]
        public void Should_benchmark_the_string_builder_method()
        {
            RepeatReverse(new StringReverserUsingStringBuilder(logger));
        }

        [Test]
        public void Should_benchmark_the_linq_method()
        {
            RepeatReverse(new StringReverserUsingLinq(logger));
        }

        [Test]
        public void Should_benchmark_the_index_swapping_method()
        {
            RepeatReverse(new StringReverserUsingIndexSwapping(logger));
        }

        [Test]
        public void Should_benchmark_the_array_reverse_method()
        {
            RepeatReverse(new StringReverserUsingArrayReverse(logger));
        }
    }
}